from datetime import datetime

from sqlalchemy import BIGINT, String, DateTime
from sqlalchemy.orm import Mapped, mapped_column

from owl_admin.ext import db
from owl_ai.domain.po import JSONEncoded


class KnowledgeBasePo(db.Model):
    """
    知识库与数据库的映射关系

    """
    __tablename__ = 'knowledge_base'
    __table_args__ = {'comment': '知识库表'}

    id: Mapped[int] = mapped_column(BIGINT, primary_key=True, comment='主键')
    name: Mapped[str] = mapped_column(String(255), comment='知识库名称')
    description: Mapped[str] = mapped_column(String(2000), comment='知识库描述')
    type: Mapped[str] = mapped_column(String(255), comment='知识库类型')
    vector_store: Mapped[JSONEncoded] = mapped_column(JSONEncoded, comment='向量库配置')
    chunk_strategy: Mapped[JSONEncoded] = mapped_column(JSONEncoded, comment='分片策略配置')
    embedding_strategy: Mapped[JSONEncoded] = mapped_column(JSONEncoded, comment='向量策略配置')
    status: Mapped[str] = mapped_column(String(255), comment='知识库状态')
    create_time: Mapped[datetime] = mapped_column(DateTime, comment='创建时间')
    update_time: Mapped[datetime] = mapped_column(DateTime, comment='更新时间')
    create_by: Mapped[str] = mapped_column(String(255), comment='创建人')
    update_by: Mapped[str] = mapped_column(String(255), comment='更新人')


class KnowledgeFilePO(db.Model):
    """
    知识库文件与数据库的映射关系
    """
    __tablename__ = 'knowledge_file'
    __table_args__ = {'comment': '知识库文件表'}

    id: Mapped[int] = mapped_column(BIGINT, primary_key=True, comment='主键')
    kid: Mapped[int] = mapped_column(BIGINT, comment='知识库id')
    file_name: Mapped[str] = mapped_column(String(255), comment='文件名')
    disk_name: Mapped[str] = mapped_column(String(2000), comment='磁盘名')
    file_type: Mapped[str] = mapped_column(String(255), comment='文件类型')
    create_time: Mapped[datetime] = mapped_column(DateTime, comment='创建时间')
    update_time: Mapped[datetime] = mapped_column(DateTime, comment='更新时间')
    create_by: Mapped[str] = mapped_column(String(255), comment='创建人')
    update_by: Mapped[str] = mapped_column(String(255), comment='更新人')
